﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.WebSockets;
using System.Windows.Media.Media3D;

namespace TestDxfDocument

{

    class cuttap2
    {
        public static void Cuttap2(Dictionary<string, Object> data)//切削丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double dim = 1;
            double scale = 5;
            /*double tcl = 4 * scale;
            double td = 4 * scale;
            double thl = 16 * scale;
            double oal = 40 * scale;
            double dmm = 3.8 * scale;
            double dn;
            double drvl;
            double lu;
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = dmm - dmm / 10.0;
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = 4 * scale;
            double p = 1*scale ;//螺距
            double h = 0.866025*scale ;//根据螺纹牙型标准中的p得知h牙高的值
            double k = 8.30;//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = 0;
            double an_ = an * pi / 180;
            double l5 = 4;
            double ap = 0;
            double γp = 5;
            double ap_ = ap * pi / 180;


            double fha = 85;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;
            */
            double tcl = 4;
            double td = 4;
            double thl = 16;
            double oal = 40;
            double dmm = 3.8;
            double dn;
            double drvl;
            double lu;


            try
            {
                drvl = 4;
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = 26;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = 4 * scale;
            double p =1 * scale;//螺距
            double h = 0.866025 * scale;//根据螺纹牙型标准中的p得知h牙高的值
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = td - h * 2;
            }
            double k =8.3;//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = 0;
            double an_ = an * pi / 180;
            double l5 = tcl;
            double ap = 0;
            double γp = 5;
            double ap_ = ap * pi / 180;


            double fha = 85;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, 0, oal + 5);
            Vector2 p0_2 = fun.Polar(p0, pi, 5);
            Vector2 p1_1 = fun.Polar(p0, pi / 2, td / 2.0 - h);
            Vector2 p1_2 = fun.Polar(p1_1, k_, (tcl * p) / Math.Cos(k_));
            Vector2 p1_3 = fun.Polar(p0, pi / -2, td / 2.0 - h);
            Vector2 p1_4 = fun.Polar(p1_3, -k_, (tcl * p) / Math.Cos(k_));
            //虚拟矩阵，不显示
            Vector2 p1 = fun.Polar(p0, pi / 2, td / 2.0);
            Vector2 p2 = fun.Polar(p1, 0, thl);
            Vector2 p3 = fun.Polar(p2, pi / -2, td / 2.0);
            Vector2 p4 = fun.Polar(p0, pi / -2, td / 2.0);
            //螺纹
            Vector2 p7 = p0;
            Vector2 p5 = p0;
            Vector2 p6 = p0;
            Vector2 p8 = p0;
            Vector2 p9 = p0;
            Vector2 p10 = p0;
            Vector2 p11 = p0;
            Vector2 p12 = p0;
            Vector2 p13 = p0;
            Vector2 p14 = p0;
            Vector2 p15 = p0;
            Vector2 p16 = p0;
            Vector2 p17 = p0;
            Vector2 p18 = p1_1;
            Vector2 p19 = p0;
            Vector2 p20 = p0;
            Vector2 p21 = p0;
            var polyline1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline1_1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline2 = Pus.AddPointsToLwPolyLine(p0);
            for (int i = 0; i < l5; i++)
            {
                if (i == 0)
                {
                    p5 = fun.Polar(p7, pi / 2, td / 2 - h);
                    p10 = new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                }
                else
                {
                    p5 = p7;
                    p10 = p13;
                }
                p6 = new Vector2(p5.X + p / 2.0, p5.Y + h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8 = fun.Inters(p5, p6, p1_1, p1_2);
                Vector2 p8_1 = fun.Polar(p8, pi / 2, h);
                p9 = fun.Inters(p6, p7, p1_1, p1_2);
                Vector2 p9_1 = fun.Polar(p9, pi / 2, h);
                p11 = new Vector2(p8.X + (td / 2 - h) / Math.Tan(fha_), -p8.Y);
                p12 = new Vector2(p9.X + (td / 2 - h) / Math.Tan(fha_), -p9.Y);
                p13 = new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p5, p10, p0_1, p0_2);
                p15 = fun.Inters(p8, p11, p0_1, p0_2);
                p16 = fun.Inters(p9, p12, p0_1, p0_2);
                p17 = fun.Inters(p7, p13, p0_1, p0_2);
                p19 = fun.Polar(p18, pi / -2, td - 2 * h);
                p20 = fun.Polar(p19, 0, (td / 2 - h) / Math.Tan(fha_));
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p8, p9, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine(p8, p8_1, p8, p9, p9_1, p9);
                polyline2 = Pus.AddPointsToLwPolyLine(p14, p10, p11, p15, p11, p12, p16, p12, p13, p17, p13);
                var polyline3 = Pus.AddPointsToLwPolyLine(p18, p19, p20);

                p21 = fun.Polar(p0, pi / 2, h);
                Vector2 p21_3 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_3);
                //dxf.AddEntity(new EntityObject[] { polyline1, polyline1_1, polyline2, polyline3, polyline4, polyline4_2 });
                fun.PolyFill(dxf, polyline1, 0.3, contour);
                fun.PolyFill(dxf, polyline1_1, 0.5, contour);
                fun.PolyFill(dxf, polyline2, 0.3, contour);
                fun.PolyFill(dxf, polyline3, 0.5, contour);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                fun.PolyFill(dxf, polyline4_2, 0.5, contour);
            }
            double a1 = (thl - p * l5) / (p);
            int a2 = (int)a1;
            for (int j = 0; j < a2; j++)
            {
                p5 = p7;
                p6 = new Vector2(p5.X + p / 2.0, p5.Y + h);
                Vector2 p6_1 = fun.Polar(p6, pi / 2, h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8 = new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                p9 = new Vector2(p6.X + (td / 2 - h) / Math.Tan(fha_), -p6.Y);
                p10 = new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p8, p5, p0_1, p0_2);
                p15 = fun.Inters(p9, p6, p0_1, p0_2);
                p16 = fun.Inters(p10, p7, p0_1, p0_2);
                polyline2 = Pus.AddPointsToLwPolyLine(p14, p8, p9, p15, p9, p10, p16, p10);
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p6, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine(p6, p6_1);
                p21 = new Vector2(0, h);
                Vector2 p21_1 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_1);
                //dxf.AddEntity(new EntityObject[] { polyline1,polyline1_1, polyline2,polyline4 , polyline4_2 });
                fun.PolyFill(dxf, polyline1, 0.3, contour);
                fun.PolyFill(dxf, polyline1_1, 0.5, contour);
                fun.PolyFill(dxf, polyline2, 0.3, contour);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                fun.PolyFill(dxf, polyline4_2, 0.5, contour);
            }
            Vector2 p22 = fun.Polar(p0, pi / -2, td / 2.0);
            Vector2 p23 = fun.Polar(p22, 0, (td / 2 - h) / Math.Tan(fha_));
            var polyline5 = Pus.AddPointsToLwPolyLine(p0, p22, p23);
            //dxf.AddEntity(new EntityObject[] { polyline5 });
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            //柄部
            Vector2 p25 = fun.Polar(p7, pi / 2, h);
            Vector2 p25_1 = new Vector2(p25.X, dn / 2.0);
            Vector2 p26 = fun.Polar(p25, pi / -2, td);
            Vector2 p27 = fun.Polar(p26, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p27_1 = new Vector2(p27.X, -dn / 2.0);
            Vector2 p28_1 = fun.Polar(p7, pi / -2, td - 2 * h);
            Vector2 p28 = fun.Polar(p28_1, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p29 = fun.Polar(p25_1, 0, lu - thl);
            Vector2 p30 = new Vector2(p29.X, dmm / 2.0);
            Vector2 p31 = fun.mirrorpoint(p29, p0_1, p0_2);
            Vector2 p32 = fun.mirrorpoint(p30, p0_1, p0_2);
            Vector2 p33 = fun.Polar(p30, 0, oal - lu);
            Vector2 p34 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p35_1 = fun.Polar(p33, pi / -2, dmm / 2.0 - dmm / 2.0 / 10.0);
            Vector2 p35 = fun.Polar(p35_1, pi, 0.42 * (oal / 40.0));
            Vector2 p36 = fun.Polar(p33, pi, drvl);
            Vector2 p37 = new Vector2(p36.X, p35.Y);
            Vector2 p38 = fun.mirrorpoint(p35, p0_1, p0_2);
            Vector2 p39 = fun.mirrorpoint(p36, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p37, p0_1, p0_2);
            Vector2 p41 = new Vector2(p35.X, p36.Y);
            Vector2 p42 = new Vector2(p38.X, p39.Y);
            var polyline6 = Pus.AddPointsToLwPolyLine(p25, p28, p27, p27_1, p31, p32, p42, p40, p38, p35, p36, p41, p30, p32, p29, p25_1);
            var polyline7 = Pus.AddPointsToLwPolyLine(p42, p40, p38, p39, p42, p39, p40, p38, p35, p36, p41, p37, p35, p37, p36, p41);
            Line line1 = new Line(p33, p34);
            Arc arc1 = fun.DrawArc5(p35, line1, p41);
            Arc arc2 = fun.DrawArc5(p42, line1, p38);
            //dxf.AddEntity(new EntityObject[] { polyline6, polyline7, arc1, arc2 });
            fun.PolyFill(dxf, polyline6, 0.5, contour);
            fun.PolyFill(dxf, polyline7, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            //颈部
            Vector2 p43 = fun.Polar(p7, pi / -2, oal);
            Vector2 p44 = fun.Inters(p0_1, p0_2, p7, p43);
            Vector2 p45 = fun.Polar(p44, 0, (lu - thl) * (1.75 / 9.95));
            Vector2 p46 = fun.Polar(p7, 0, (lu - thl) * (1.75 / 9.95));
            Vector2 p47 = fun.Polar(p28, 0, (lu - thl) * (3.5 / 9.95));
            p47 = fun.Polar(p28, 0, p45.X - p44.X);
            Vector2 p45_1 = fun.Polar(fun.Polar(p45, 0, (lu - (thl)) * (4.5 / 50.0)), pi / 2, fun.CalDistance(p45, p46) / 2.0);
            Vector2 p48_1 = fun.Polar(p45_1, pi / -2, oal);
            Vector2 p48 = fun.Inters(fun.Polar(p27, pi / 2, (dmm - dn) / 2.0), fun.Polar(p31, pi / 2, (dmm - dn) / 2.0), p45_1, p48_1);
            var polyline13 = Pus.AddPointsToLwPolyLine(p44, p45, p45_1, p46, p7);
            polyline13.Vertexes[1].Bulge = Math.Tan((60 * pi / 180) / 4);
            polyline13.Vertexes[2].Bulge = Math.Tan((60 * pi / 180) / 4);
            //dxf.AddEntity(polyline13);
            var polyline14 = Pus.AddPointsToLwPolyLine(p28, p47, p48);
            polyline14.Vertexes[1].Bulge = -Math.Tan((60 * pi / 180) / 4);
            //dxf.AddEntity(polyline14);
            fun.PolyFill(dxf, polyline13, 0.5, contour);
            fun.PolyFill(dxf, polyline14, 0.5, contour);
            //侧面
            try
            {
                drvsc = Convert.ToDouble(data["drvsc"]) * scale;

            }
            catch
            {
                drvsc = td;
            }
            Vector2 p50 = p0;
            Vector2 p51 = p0;
            Vector2 p49_1 = fun.Polar(p0, pi, oal / 1.5);
            Vector2 p49 = fun.Polar(p0, 0, oal + oal / 3.0);
            p50 = fun.Polar(p49, pi / 2, drvsc / 2.0);
            Vector2 p50_1 = fun.Polar(p50, pi + pi / 4, drvsc / 10.0);
            Vector2 p50_2 = fun.Polar(p50, pi / -4, drvsc / 10.0);
            p51 = fun.Polar(p49, 0, drvsc / 2.0);
            Vector2 p51_1 = fun.Polar(p51, pi - pi / 4, drvsc / 10.0);
            Vector2 p51_2 = fun.Polar(p51, pi + pi / 4, drvsc / 10.0);
            Vector2 p52 = fun.Polar(p49, pi / -2, drvsc / 2.0);
            Vector2 p52_1 = fun.Polar(p52, pi / 4, drvsc / 10.0);
            Vector2 p52_2 = fun.Polar(p52, pi - pi / 4, drvsc / 10.0);
            Vector2 p53 = fun.Polar(p49, pi, drvsc / 2.0);
            Vector2 p53_1 = fun.Polar(p53, pi / -4, drvsc / 10.0);
            Vector2 p53_2 = fun.Polar(p53, pi / 4, drvsc / 10.0);
            var polyline9 = Pus.AddPointsToLwPolyLine(p50_1, p50_2, p51_1, p51_2, p52_1, p52_2, p53_1, p53_2, p50_1);
            polyline9.Vertexes[0].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[2].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[4].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[6].Bulge = -Math.Tan((90 * pi / 180) / 4);
            fun.PolyFill(dxf, polyline9, 0.5, contour);
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = polyline9.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = polyline9.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)polyline9.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)polyline9.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 3 * (oal / 40.0), hline1, harc1, hatching);
            //左视
            Circle circle1 = new Circle(p49_1, dmm / 2.0);
            Circle circle2 = new Circle(p49_1, td / 2.0);//外轮廓参照
            Arc arc2_1 = fun.DrawArc4(fun.Polar(p49_1, 0, td / 2.0), circle2.Radius, fun.Polar(p49_1, 179.99 * pi / 180, td / 2.0), 0);
            Vector2 p54 = fun.Polar(p49_1, pi / 2, td / 2.0 + 2 * h);
            Vector2 p54_1 = fun.Polar(fun.PointRotate(p54, p49_1, ap_), pi / -4, dmm * (1 / 19.0));
            Vector2 p55 = fun.Polar(p49_1, pi / 6, td / 2.0 + 2 * h);
            Vector2 p56 = fun.Polar(p49_1, pi / 2, td / 2.0 - td / 15.0 + 2 * h);
            Vector2 p57 = fun.Polar(p49_1, pi / 6, td / 2.0 - td / 15.0 + 2 * h);
            Circle circle3 = new Circle(p54_1, dmm / 2.0);
            circle3.Linetype = Linetype.Dashed;
            circle3.Lineweight = Lineweight.W35;
            circle3.Layer = centre;
            dxf.AddEntity(circle3);
            for (int j = 0; j < 3; j++)
            {
                Arc arc5 = fun.DrawArc(p55, p49_1, p54);
                Vector2 arc5_1 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.StartAngle * pi / 180, arc5.Radius), 120 * j * pi / 180);
                Vector2 arc5_2 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.EndAngle * pi / 180, arc5.Radius), 120 * j * pi / 180);
                arc5 = fun.DrawArc(arc5_1, Pus.ToV2(arc5.Center), arc5_2);
                Arc arc7 = fun.DrawArc(p57, p49_1, p56);
                Vector2 arc7_1 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.StartAngle * pi / 180, arc7.Radius), 120 * j * pi / 180);
                Vector2 arc7_2 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.EndAngle * pi / 180, arc7.Radius), 120 * j * pi / 180);
                arc7 = fun.DrawArc(arc7_1, Pus.ToV2(arc7.Center), arc7_2);
                Arc arc6 = fun.Rotatingcircle(arc5, p54, ap_);
                Vector2 arc6_1 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.StartAngle * pi / 180, arc6.Radius), 120 * j * pi / 180);
                Vector2 arc6_2 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.EndAngle * pi / 180, arc6.Radius), -120 * j * pi / 180);
                arc6 = fun.DrawArc(arc6_1, Pus.ToV2(arc6.Center), arc6_2);
                Arc arc8 = fun.Rotatingcircle(arc7, p56, ap_);
                Vector2 arc8_1 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.StartAngle * pi / 180, arc8.Radius), 120 * j * pi / 180);
                Vector2 arc8_2 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.EndAngle * pi / 180, arc8.Radius), -120 * j * pi / 180);
                arc8 = fun.DrawArc(arc8_1, Pus.ToV2(arc8.Center), arc8_2);
                if (ap == 0)
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180 - pi / 3.0, arc5.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc7.Center), (arc7.StartAngle) * pi / 180 - pi / 3.0, arc7.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180, arc5.Radius), p59, p58);
                    //dxf.AddEntity(new EntityObject[] { arc5, arc7, arc9 });
                    fun.drawBArc(dxf, arc5, 0.5, contour);
                    fun.drawBArc(dxf, arc7, 0.5, contour);
                    fun.drawBArc(dxf, arc9, 0.5, contour);
                }
                else
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180 - pi / 3.0, arc6.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc8.Center), (arc8.StartAngle) * pi / 180 - pi / 3.0, arc8.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180, arc6.Radius), p59, p58);
                    //dxf.AddEntity(new EntityObject[] { arc6, arc8, arc9 });
                    fun.drawBArc(dxf, arc6, 0.5, contour);
                    fun.drawBArc(dxf, arc8, 0.5, contour);
                    fun.drawBArc(dxf, arc9, 0.5, contour);
                }

                //fun.PointRotate(p49_1, p54, 120 * pi / 180);//
            }

            //中心线
            Line line1_1 = new Line(p0_1, p0_2);
            line1_1.Linetype = Linetype.DashDot;
            line1_1.Lineweight = Lineweight.W25;
            line1_1.Layer = centre;
            dxf.AddEntity(line1_1);


            //标注

            if (dim == 0)
            {
                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 - h);
                Vector2 v2 = fun.Polar(p0, pi / -2, td / 2 - h);
                Vector2 v3 = fun.Polar(p0, pi / 2, td / 2.0 + h);
                Vector2 v4 = fun.Polar(v3, 0, l5 * p + p / 2.0);
                Vector2 v5 = fun.mirrorpoint(v4, p0_1, p0_2);
                Vector2 v6 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);
                Vector2 v8 = fun.PointRotate(p54, p55, ap_);
                Vector2 v9 = fun.Polar(p34, pi / 2, fun.CalDistance(p34, p33) / 2.0);
                Vector2 v10 = fun.Polar(v9, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v11 = fun.Polar(v10, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v12 = fun.Polar(p53, pi / -2, dmm);
                double L = 5 * (oal / 40.0);
                double height = 1.2 * (oal / 40.0);
                double arrowsize = (1.6 * (oal / 40.0));
                fun.dimrot1(dxf, v1, v2, 90, L, 2, height, arrowsize, 0.9, "  TCPD", "", "");
                fun.dimrot1(dxf, v4, v5, 90, L * 3, 2, height, arrowsize, 0.9, "TD", "", "");
                fun.dimrot1(dxf, p33, p34, -90, L, 2, height, arrowsize, 0.9, "DCONMS", "", "");
                fun.dimrot1(dxf, p0, v5, 180, L * 1.5, 2, height, arrowsize, 0.9, "TCL", "", "");
                fun.dimrot1(dxf, p0, p44, 0, L, 2, height, arrowsize, 0.9, "THL", "", "");
                fun.dimrot1(dxf, p54, fun.Polar(p54, 0, 0.1), 0, L / 2.0, 2, height, arrowsize, 0.9, " γp", "", "");
                fun.dimrot1(dxf, v8, fun.Polar(v8, pi / -2, 0.1), -155, L, 2, height, arrowsize, 0.9, " αp", "", "");
                fun.dimrot1(dxf, p34, p33, 90, L, 2, height, arrowsize, 0.9, " A-A", "", "");
                fun.Singlelinearrow(dxf, "A", v9, 180, v10, v11, height, arrowsize);
                Text txt1 = new Text("A-A", v12, height, 0);
                dxf.AddEntity(txt1);
                try
                {
                    dn = Convert.ToDouble(data["dn"]) * scale;
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                    fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                }
                catch
                { }
                try
                {
                    lu = Convert.ToDouble(data["lu"]) * scale;
                    Vector2 v7 = fun.Polar(p0, 0, lu);
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  LU", "", "");
                }
                catch
                {
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                }
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");
                }
                catch { }
                /*
                Vector2 v7 = fun.Polar(p0, 0, lu);
                fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                fun.dimrot1(dxf, p0, v7, 0, L *1.5, 2, height, arrowsize, 0.9, "  LU", "", "");
                fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");*/
            }
            else
            {

                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 - h);
                Vector2 v2 = fun.Polar(p0, pi / -2, td / 2 - h);
                Vector2 v3 = fun.Polar(p0, pi / 2, td / 2.0 + h);
                Vector2 v4 = fun.Polar(v3, 0, l5 * p);
                Vector2 v5 = fun.mirrorpoint(v4, p0_1, p0_2);
                Vector2 v6 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);
                Vector2 v8 = fun.PointRotate(p54, p55, ap_);
                Vector2 v9 = fun.Polar(p34, pi / 2, fun.CalDistance(p34, p33) / 2.0);
                Vector2 v10 = fun.Polar(v9, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v11 = fun.Polar(v10, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v12 = fun.Polar(p53, pi / -2, dmm);
                double tcpd = td - h * 2;
                double L = 5 * (oal / 40.0);
                double height = 1.2 * (oal / 40.0);
                double arrowsize = (1.6 * (oal / 40.0));
                fun.dimrot1(dxf, v1, v2, 90, L, 2, height, arrowsize, 0.9, "  TCPD=" + tcpd / scale, "", "");
                fun.dimrot1(dxf, v4, v5, 90, L * 3, 2, height, arrowsize, 0.9, "TD=" + td / scale, "", "");
                fun.dimrot1(dxf, p33, p34, -90, L, 2, height, arrowsize, 0.9, "DCONMS=" + dmm / scale, "", "");
                fun.dimrot1(dxf, p0, v5, 180, L * 1.5, 2, height, arrowsize, 0.9, "TCL=" + tcl / scale, "", "");
                fun.dimrot1(dxf, p0, p44, 0, L, 2, height, arrowsize, 0.9, "THL=" + thl / scale, "", "");
                fun.dimrot1(dxf, p54, fun.Polar(p54, 0, 0.1), 0, L / 2.0, 2, height, arrowsize, 0.9, "  γp=" + γp, "", "");
                fun.dimrot1(dxf, v8, fun.Polar(v8, pi / -2, 0.1), -155, L, 2, height, arrowsize, 0.9, " αp=" + ap, "", "");
                fun.Singlelinearrow(dxf, "A", v9, 180, v10, v11, height, arrowsize);
                Text txt1 = new Text("A-A", v12, height, 0);
                dxf.AddEntity(txt1);

                try
                {
                    dn = Convert.ToDouble(data["dn"]) * scale;
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN=" + dn / scale, "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                    fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC=" + drvsc / scale, "", "");
                }
                catch
                { }
                try
                {
                    lu = Convert.ToDouble(data["lu"]) * scale;
                    Vector2 v7 = fun.Polar(p0, 0, lu);
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL=" + oal / scale, "", "");
                    fun.dimrot1(dxf, p0, v7, 0, L * 1.5, 2, height, arrowsize, 0.9, "  LU=" + lu / scale, "", "");
                }
                catch
                {
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL=" + oal / scale, "", "");
                }
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL=" + drvl / scale, "", "");
                }
                catch { }
                /*
                Vector2 v7 = fun.Polar(p0, 0, lu);
                fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                fun.dimrot1(dxf, p0, v7, 0, L *1.5, 2, height, arrowsize, 0.9, "  LU", "", "");
                fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");*/
            }
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}